package com.accompany.dialog;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;


import com.accompany.R;
import com.accompany.listener.OnQuiteDialogClickListener;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：菲菲 on 2020/10/14 17:22
 * <p>
 * company：中星电子
 */
public class RoundCornerDialog extends AlertDialog {
    @BindView(R.id.tv_des)
    TextView tvMessage;
    @BindView(R.id.tv_cancel)
    TextView mCancle;
    @BindView(R.id.tv_confirm)
    TextView mConfirm;
    private OnQuiteDialogClickListener listener;
    private String message,mcancle, mconfirm;
    /**
     * 一个参数的构造方法
     * @param context 上下文对象
     */
    public RoundCornerDialog(Context context, String message, String mconfirm, String mcancle, OnQuiteDialogClickListener listener) {
        super(context, R.style.exitdialog);
        this.message = message;
        this.listener = listener;
        this.mconfirm = mconfirm;
        this.mcancle = mcancle;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_layout_round);
        ButterKnife.bind(this);
        //设置背景透明，不然会出现白色直角问题
        Window window = getWindow();
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setCanceledOnTouchOutside(false);
        //初始化布局控件
        initView();
        //设置参数必须在show之后，不然没有效果
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.gravity = Gravity.CENTER;
        getWindow().setAttributes(params);
    }
    private void initView() {
        tvMessage.setText(message);
        mCancle.setText(mcancle);
        mConfirm.setText(mconfirm);
    }
    @OnClick({R.id.tv_cancel, R.id.tv_confirm})
    public void OnClick(View v) {
        switch (v.getId()) {
            case R.id.tv_cancel:
                if (listener != null) {
                    listener.onCancel(this);
                }
                break;
            case R.id.tv_confirm:
                if (listener != null) {
                    listener.onConfirm(this);
                }
                break;
            default:
                break;
        }

    }
}